package org.apache.flink.runtime.resourceconsumer;

import java.util.concurrent.CompletableFuture;

import org.apache.flink.api.common.time.Time;
import org.apache.flink.runtime.allocatedeploy.execution.CommandDescriptor;
import org.apache.flink.runtime.allocatedeploy.execution.ExecutionID;
import org.apache.flink.runtime.clusterframework.types.AllocationID;
import org.apache.flink.runtime.consumermanager.slots.ProviderManagerGateway;
import org.apache.flink.runtime.messages.Acknowledge;
import org.apache.flink.runtime.resourceprovider.ResourceProviderGateway;
import org.apache.flink.util.Preconditions;

/** 
 * Implementation of the {@link ProviderManagerGateway} for RPC system. 
 * 资源消费者与任务管理器通讯网关
 */
public class RpcProviderManagerGateway implements ProviderManagerGateway {

    private final ResourceProviderGateway resourceProviderGateway;

    private final ConsumingMasterId consumingMasterId;

    public RpcProviderManagerGateway(ResourceProviderGateway taskExecutorGateway, ConsumingMasterId consumingMasterId) {
        this.resourceProviderGateway = Preconditions.checkNotNull(taskExecutorGateway);
        this.consumingMasterId = Preconditions.checkNotNull(consumingMasterId);
    }

    @Override
    public String getAddress() {
        return resourceProviderGateway.getAddress();
    }

    @Override
    public CompletableFuture<Acknowledge> freeSlot(
            AllocationID allocationId, Throwable cause, Time timeout) {
        return resourceProviderGateway.freeSlot(allocationId, cause, timeout);
    }

	@Override
	public CompletableFuture<Acknowledge> submitCommand(CommandDescriptor commandDescriptor, 
					ConsumingMasterId consumingMasterId, Time timeout) {
		return resourceProviderGateway.submitCommand(commandDescriptor, consumingMasterId, timeout);
	}

	@Override
	public CompletableFuture<Acknowledge> cancelCommand(ExecutionID executionID, Time timeout) {
		// TODO Auto-generated method stub
		return null;
	}

}
